package offer;

@FunctionalInterface
public interface FindMedianSortedArrays {
    double findMedianSortedArrays(int[] nums1,int[] nums2);
}

class FindMedianSortedArraysImpl1 implements  FindMedianSortedArrays{

    /**
     * 考虑平凡情况
     * nums1，nums2 存在空
     * nums1，并上nums2递增，
     * @param nums1
     * @param nums2
     * @return
     */
    @Override
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        if(nums1.length == 0 && nums2.length == 0){
            return 0;
        }else if(nums1.length == 0){
            return quickSelect(nums2, nums2.length/2);
        }else if(nums2.length == 0){
            return quickSelect(nums1,nums1.length/2);
        }
        if(nums1[nums1.length - 1] <= nums2[0]){
           if(nums1.length > nums2.length){
               return quickSelect(nums2,(nums1.length + nums2.length)/2);
           }else{
               return quickSelect(nums2,(nums2.length-nums1.length)/2);
           }
        }else if(nums2[nums2.length - 1] <= nums1[0]){
            if(nums1.length > nums2.length){
                return quickSelect(nums1,(nums1.length-nums2.length)/2);
            }else{
                return quickSelect(nums2,(nums1.length + nums2.length)/2);
            }
        }

        return 0;
    }

    public double quickSelect(int[] nums,int k){
        return 0;
    }
}
